<?php

/**
 * Link form base class.
 *
 * @method Link getObject() Returns the current form's model object
 *
 * @package    25Mails
 * @subpackage form
 * @author     fabio.lorenzini@25solutions.com
 * @version    SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
 */
abstract class BaseLinkForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'link_id'     => new sfWidgetFormInputHidden(),
      'template_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Template'), 'add_empty' => false)),
      'name'        => new sfWidgetFormInputText(),
      'target_url'  => new sfWidgetFormTextarea(),
      'created_at'  => new sfWidgetFormDateTime(),
      'updated_at'  => new sfWidgetFormDateTime(),
      'deleted_at'  => new sfWidgetFormDateTime(),
    ));

    $this->setValidators(array(
      'link_id'     => new sfValidatorChoice(array('choices' => array($this->getObject()->get('link_id')), 'empty_value' => $this->getObject()->get('link_id'), 'required' => false)),
      'template_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Template'))),
      'name'        => new sfValidatorString(array('max_length' => 255)),
      'target_url'  => new sfValidatorRegex(array('pattern' => '/^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i', 'required' => false)),
      'created_at'  => new sfValidatorDateTime(),
      'updated_at'  => new sfValidatorDateTime(),
      'deleted_at'  => new sfValidatorDateTime(array('required' => false)),
    ));

    $this->validatorSchema->setPostValidator(
      new sfValidatorDoctrineUnique(array('model' => 'Link', 'column' => array('template_id', 'name')))
    );

    $this->widgetSchema->setNameFormat('link[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'Link';
  }

}
